package com.kvn.unloadclass;

/**
 * @author wzy
 * @date 2017年9月20日 下午6:02:18
 */
public class TestClassUnLoad {
	public static void main(String[] args) throws Exception {
		SimpleURLClassLoader loader = new SimpleURLClassLoader();
		// 用自定义的加载器加载A
		Class clazzA = loader.load("com.kvn.unloadclass.A");
		Object a = clazzA.newInstance();
		// 清除相关引用
		a = null;
		clazzA = null;
		loader = null;
		// 执行一次gc垃圾回收
		System.gc();
		System.out.println("GC over");
	}
	
	/**
	 * 运行前配置VM参数: -verbose:class，用于查看class的加载与卸载情况
	 * <pre>
	 * [Opened C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.Object from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.io.Serializable from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.Comparable from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.CharSequence from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.String from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.reflect.GenericDeclaration from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.reflect.Type from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.reflect.AnnotatedElement from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.Class from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.Cloneable from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.ClassLoader from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.System from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.Throwable from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.Error from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.ThreadDeath from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.Exception from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.RuntimeException from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.security.ProtectionDomain from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * ..........
	 * [Loaded java.net.URI from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.net.URI$Parser from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded com.kvn.unloadclass.A from file:/E:/gitWorkspace/btracedemo/bin/]
	 * [Unloading class com.kvn.unloadclass.A]
	 * GC over
	 * [Loaded java.lang.Shutdown from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * [Loaded java.lang.Shutdown$Lock from C:\Program Files\Java\jdk1.7.0_79\jre\lib\rt.jar]
	 * </pre>
	 */
}
